package com.ld.control.business.user.controller;

import com.ld.control.business.user.service.UserAccountService;
import com.ld.control.business.user.vo.req.UserAccountReqVo;
import com.ld.control.business.user.vo.resp.UserAccountRespVo;
import com.ld.control.business.user.vo.req.UserLoginReqVo;
import com.ld.control.business.user.vo.resp.UserLoginRespVo;
import com.ld.control.common.vo.GeneratePageListVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "用户相关接口")
@RestController
public class UserAccountController {

    @Autowired
    private UserAccountService userAccountService;

    @PostMapping("/api/centralControl/user/add")
    @Operation(summary = "添加用户")
    public ResultResponse<ResultResponseEnum> add(@RequestBody UserAccountReqVo reqVo) {
        userAccountService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/user/update")
    @Operation(summary = "修改用户信息")
    public ResultResponse<ResultResponseEnum> update(@RequestBody UserAccountReqVo reqVo) {
        userAccountService.update(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/user/delete")
    @Operation(summary = "删除用户信息")
    public ResultResponse<ResultResponseEnum> delete(@RequestParam Long id) {
        userAccountService.delete(id);
        return ResultResponse.success();
    }

    @GetMapping("/api/centralControl/user/getPageList")
    @Operation(summary = "查询用户列表")
    public ResultResponse<GeneratePageListVo<UserAccountRespVo>> getPageList(
            @RequestParam(required = false) String accountName,
            @RequestParam(required = false) String realName,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) String mobile,
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "10") Integer size
    ) {
        GeneratePageListVo<UserAccountRespVo> pageList = userAccountService.getPageList(accountName, realName, status, mobile, current, size);
        return ResultResponse.success(pageList);
    }

    @GetMapping("/api/centralControl/user/getById")
    @Operation(summary = "查询用户详情")
    public ResultResponse<UserAccountRespVo> getById(@RequestParam Long id) {
        UserAccountRespVo userAccountRespVo = userAccountService.getById(id);
        return ResultResponse.success(userAccountRespVo);
    }

    @PostMapping("/api/centralControl/user/userLogin")
    @Operation(summary = "用户登录")
    public ResultResponse<UserLoginRespVo> userLogin(@RequestBody UserLoginReqVo reqVo) {
        UserLoginRespVo userLoginRespVo = userAccountService.userLogin(reqVo);
        return ResultResponse.success(userLoginRespVo);
    }

    @GetMapping("/api/centralControl/user/getCurrentUser")
    @Operation(summary = "获取当前登录用户详情")
    public ResultResponse<UserAccountRespVo> getCurrentUser() {
        UserAccountRespVo currentUser = userAccountService.getCurrentUser();
        return ResultResponse.success(currentUser);
    }

}
